package cn.org.donald.framework.constant;

import cn.org.donald.framework.property.FileProperties;
import cn.org.donald.framework.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author ： Donald
 * @date ： 2020/10/24 13:55
 * @description：
 */
@Component
public class FileConstant {

    @Autowired
    private FileProperties fileProperties;

    /**
     * 文件上传路径
     */

    public static String FILE_PATH_UPLOAD;

    /**
     * 文件访问路径
     */
    public static String FILE_PATH_REQUEST;

    /**
     * 文件真实路径
     */
    public static String FILE_PATH_REAL;

    @Bean
    public void setFILE_PATH_UPLOAD(){
        String filePathUpload = fileProperties.getUpload();
        FILE_PATH_UPLOAD = realName(filePathUpload);
        FILE_PATH_REAL = "file:" + realName(filePathUpload);
    }
    @Bean
    public void setFILE_PATH_REQUEST(){
        String filePathRequest = fileProperties.getRequest();
        FILE_PATH_REQUEST = realName(filePathRequest);
    }


    private static String realName(String name){
        name = name.endsWith("/")? name : name + "/";
        return name.replaceAll("/",FileUtil.separator);
    }
}
